package com.mysteel.cyx.demo.service;

import com.alibaba.excel.ExcelWriter;
import com.mysteel.cyx.demo.biz.export.bo.AssetAllocationBO;
import com.mysteel.cyx.demo.biz.export.bo.ComplianceMonitoringDailyB0;
import com.mysteel.cyx.demo.biz.export.bo.ComplianceMonitoringErrorBO;
import com.mysteel.cyx.demo.biz.export.bo.ComplianceMonitoringWarnB0;
import com.mysteel.cyx.demo.biz.export.complianceMonitoringDailyReport;
import org.springframework.stereotype.Service;

import javax.imageio.IIOException;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Vicky(陈烟星)
 * @date 2024/6/18 13:52
 */
@Service
public class ComplianceMonitoringDailyReportService {

    public void export(ExcelWriter excelWriter) throws IOException {

        complianceMonitoringDailyReport dailyReport = new complianceMonitoringDailyReport();
        ComplianceMonitoringDailyB0 complianceMonitoringDailyB0 = buildComplianceMonitoringDailyB0();
        dailyReport.exportComplianceMonitoringDailyReport(excelWriter, complianceMonitoringDailyB0);
    }

    public ComplianceMonitoringDailyB0 dataPrepataion() {
        return buildComplianceMonitoringDailyB0();
    }

    private ComplianceMonitoringDailyB0 buildComplianceMonitoringDailyB0() {
        ComplianceMonitoringDailyB0 complianceMonitoringDailyB0 = new ComplianceMonitoringDailyB0();
        complianceMonitoringDailyB0.setBusinessDate(20240618);
        complianceMonitoringDailyB0.setAssetAllocationBoList(buildAssetAllocationBOList());
        complianceMonitoringDailyB0.setComplianceMonitoringErrorBoList(buildComplianceMonitoringErrorBoList());
        complianceMonitoringDailyB0.setComplianceMonitoringWarnBoList(buildComplianceMonitoringWarnBoList());
        return complianceMonitoringDailyB0;
    }

    private List<ComplianceMonitoringWarnB0> buildComplianceMonitoringWarnBoList() {
        List<ComplianceMonitoringWarnB0> list = new ArrayList<>();

        ComplianceMonitoringWarnB0 complianceMonitoringWarnB0 = new ComplianceMonitoringWarnB0();
        complianceMonitoringWarnB0.setSerialNo(1);
        complianceMonitoringWarnB0.setRuleCode("0001");
        complianceMonitoringWarnB0.setRuleSummary("产品1的规则说明");
        complianceMonitoringWarnB0.setFundName("产品1");
        complianceMonitoringWarnB0.setWarnOperation(1);
        complianceMonitoringWarnB0.setCalcValue(BigDecimal.ZERO);
        complianceMonitoringWarnB0.setSetValue(BigDecimal.ZERO);
        complianceMonitoringWarnB0.setAvgValue(BigDecimal.ZERO);
        complianceMonitoringWarnB0.setViolationDayCount(new BigDecimal("1"));
        //complianceMonitoringWarnB0.setContinueViolationDays(1);
        //complianceMonitoringWarnB0.setAdjustableDayCount(1);
        complianceMonitoringWarnB0.setRemarkLong("产品1的备注:这里我给大家详细说一下。首先是我这边定义的如果columnWidth 长度大于10，就赋值为20，否则就赋值为10，你们可以自行调整。 在计算长度的那个方法中，有个switch 方法，其中对字符串，布尔，还有数值型进行区分。然后去用不同的公式计算。这里会遇到一个坑，如果你的导出的文档有很多数字，比如金额什么的。就可以把case NUMBER删掉，因为可能列宽不够导致导出来的值是”###### 版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明 原文链接：https://blog.csdn.net/qq_51657546/article/details/138667869");


        ComplianceMonitoringWarnB0 complianceMonitoringWarnB01 = new ComplianceMonitoringWarnB0();
        complianceMonitoringWarnB01.setSerialNo(2);
        complianceMonitoringWarnB01.setRuleCode("0002");
        complianceMonitoringWarnB01.setRuleSummary("产品2的规则说明");
        complianceMonitoringWarnB01.setFundName("产品2");
        complianceMonitoringWarnB01.setWarnOperation(1);
        complianceMonitoringWarnB01.setCalcValue(new BigDecimal("-2.142334"));
        complianceMonitoringWarnB01.setSetValue(BigDecimal.ONE);
        complianceMonitoringWarnB01.setAvgValue(BigDecimal.ONE);
        complianceMonitoringWarnB01.setViolationDayCount(new BigDecimal("2"));
        //complianceMonitoringWarnB01.setContinueViolationDays(2);
        //complianceMonitoringWarnB01.setAdjustableDayCount(2);
        complianceMonitoringWarnB01.setRemarkLong("产品2的备注");

        list.add(complianceMonitoringWarnB0);
        list.add(complianceMonitoringWarnB01);
        return list;
    }

    private List<ComplianceMonitoringErrorBO> buildComplianceMonitoringErrorBoList() {
        List<ComplianceMonitoringErrorBO> list = new ArrayList<>();
        ComplianceMonitoringErrorBO complianceMonitoringErrorBO = new ComplianceMonitoringErrorBO();
        complianceMonitoringErrorBO.setSerialNo(1);
        complianceMonitoringErrorBO.setRuleCode("0001");
        complianceMonitoringErrorBO.setRuleSummary("产品1的规则说明:这里我给大家详细说一下。首先是我这边定义的如果columnWidth 长度大于10，就赋值为20，否则就赋值为10，你们可以自行调整。 在计算长度的那个方法中，有个switch 方法，其中对字符串，布尔，还有数值型进行区分。然后去用不同的公式计算。这里会遇到一个坑，如果你的导出的文档有很多数字，比如金额什么的。就可以把case NUMBER删掉，因为可能列宽不够导致导出来的值是”###### 版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明 原文链接：https://blog.csdn.net/qq_51657546/article/details/138667869");
        complianceMonitoringErrorBO.setFundName("产品1");
        complianceMonitoringErrorBO.setWarnOperation(2);
        complianceMonitoringErrorBO.setCalcValue(BigDecimal.ZERO);
        complianceMonitoringErrorBO.setSetValue(BigDecimal.ZERO);
        complianceMonitoringErrorBO.setAvgValue(new BigDecimal("111.12"));
        complianceMonitoringErrorBO.setViolationDayCount(new BigDecimal(1));
        complianceMonitoringErrorBO.setContinueViolationDays(1);
        complianceMonitoringErrorBO.setMinContinueViolationDays(1);
        //complianceMonitoringErrorBO.setAdjustableDayCount(1);
        complianceMonitoringErrorBO.setRemarkLong("产品1的备注");

        ComplianceMonitoringErrorBO complianceMonitoringErrorBO1 = new ComplianceMonitoringErrorBO();
        complianceMonitoringErrorBO1.setSerialNo(1);
        complianceMonitoringErrorBO1.setRuleCode("0002");
        complianceMonitoringErrorBO1.setRuleSummary("产品2的规则说明");
        complianceMonitoringErrorBO1.setFundName("产品2");
        complianceMonitoringErrorBO1.setWarnOperation(2);
        complianceMonitoringErrorBO1.setCalcValue(BigDecimal.ONE);
        complianceMonitoringErrorBO1.setSetValue(BigDecimal.ONE);
        complianceMonitoringErrorBO1.setAvgValue(new BigDecimal("7.021112"));
        complianceMonitoringErrorBO1.setViolationDayCount(new BigDecimal(2));
        complianceMonitoringErrorBO1.setContinueViolationDays(2);
        complianceMonitoringErrorBO1.setMinContinueViolationDays(2);
        //complianceMonitoringErrorBO1.setAdjustableDayCount(2);
        complianceMonitoringErrorBO1.setDisplayUnit(6);
        complianceMonitoringErrorBO1.setRemarkLong("产品2的备注");

        ComplianceMonitoringErrorBO complianceMonitoringErrorBO2 = new ComplianceMonitoringErrorBO();
        complianceMonitoringErrorBO2.setSerialNo(1);
        complianceMonitoringErrorBO2.setRuleCode("0003");
        complianceMonitoringErrorBO2.setRuleSummary("产品3的规则说明");
        complianceMonitoringErrorBO2.setFundName("产品2");
        complianceMonitoringErrorBO2.setWarnOperation(2);
        complianceMonitoringErrorBO2.setCalcValue(new BigDecimal("10.1111"));
        complianceMonitoringErrorBO2.setSetValue(new BigDecimal("-9.23456"));
        complianceMonitoringErrorBO2.setAvgValue(new BigDecimal("-7.23456"));
        complianceMonitoringErrorBO2.setViolationDayCount(new BigDecimal(3));
        complianceMonitoringErrorBO2.setContinueViolationDays(3);
        complianceMonitoringErrorBO2.setMinContinueViolationDays(3);
        //complianceMonitoringErrorBO2.setAdjustableDayCount(3);
        complianceMonitoringErrorBO2.setRemarkLong("'产品3的备注'");
        complianceMonitoringErrorBO2.setDisplayUnit(1);

        list.add(complianceMonitoringErrorBO);
        list.add(complianceMonitoringErrorBO1);
        list.add(complianceMonitoringErrorBO2);
        return list;
    }


    private List<AssetAllocationBO> buildAssetAllocationBOList() {
        List<AssetAllocationBO> list = new ArrayList<>();

        AssetAllocationBO assetAllocationBO = new AssetAllocationBO();
        assetAllocationBO.setSerialNo(1);
        assetAllocationBO.setFundName("产品1");
        assetAllocationBO.setFaAccountNo("fund-1");
        assetAllocationBO.setNav(BigDecimal.ZERO);
        assetAllocationBO.setFundNetValue(new BigDecimal("1.1"));
        assetAllocationBO.setStockFullPriceAsset(new BigDecimal("2.3"));
        assetAllocationBO.setStockFullAstNavRatio(new BigDecimal("2.4"));
        assetAllocationBO.setBondFullPriceAsset(new BigDecimal("3.1"));
        assetAllocationBO.setBondFullAstNavRatio(new BigDecimal("3.2"));
        assetAllocationBO.setFundFullPriceAsset(new BigDecimal("3.1"));
        assetAllocationBO.setFundFullAstNavRatio(new BigDecimal("3.2"));
        assetAllocationBO.setCashFullPriceAsset(new BigDecimal("3.2"));
        assetAllocationBO.setCashFullAstNavRatio(new BigDecimal("3.2"));
        assetAllocationBO.setFmProductFullPriceAsset(new BigDecimal("3.2"));
        assetAllocationBO.setFmProductFullAstNavRatio(new BigDecimal("3.2"));
        assetAllocationBO.setOtherFullPriceAsset(new BigDecimal("3.2"));
        assetAllocationBO.setOtherFullAstNavRatio(new BigDecimal("3.2"));
        assetAllocationBO.setDebtFullPriceAsset(new BigDecimal("3.2"));
        assetAllocationBO.setDebtFullAstNavRatio(new BigDecimal("3.2"));

        AssetAllocationBO assetAllocationBO1 = new AssetAllocationBO();
        assetAllocationBO1.setSerialNo(1);
        assetAllocationBO1.setFundName("产品2");
        assetAllocationBO1.setFaAccountNo("fund-2");
        assetAllocationBO1.setNav(BigDecimal.ONE);
        assetAllocationBO1.setFundNetValue(new BigDecimal("2.2"));
        assetAllocationBO1.setStockFullPriceAsset(new BigDecimal("3.4"));
        assetAllocationBO1.setStockFullAstNavRatio(new BigDecimal("3.5"));
        assetAllocationBO1.setBondFullPriceAsset(new BigDecimal("4.1"));
        assetAllocationBO1.setBondFullAstNavRatio(new BigDecimal("4.2"));
        assetAllocationBO1.setFundFullPriceAsset(new BigDecimal("4.1"));
        assetAllocationBO1.setFundFullAstNavRatio(new BigDecimal("4.2"));
        assetAllocationBO1.setCashFullPriceAsset(new BigDecimal("4.2"));
        assetAllocationBO1.setCashFullAstNavRatio(new BigDecimal("4.2"));
        assetAllocationBO1.setFmProductFullPriceAsset(new BigDecimal("4.2"));
        assetAllocationBO1.setFmProductFullAstNavRatio(new BigDecimal("4.2"));
        assetAllocationBO1.setOtherFullPriceAsset(new BigDecimal("4.2"));
        assetAllocationBO1.setOtherFullAstNavRatio(new BigDecimal("4.2"));
        assetAllocationBO1.setDebtFullPriceAsset(new BigDecimal("4.2"));
        assetAllocationBO1.setDebtFullAstNavRatio(new BigDecimal("4.2"));


        AssetAllocationBO assetAllocationBO2 = new AssetAllocationBO();
        assetAllocationBO2.setSerialNo(1);
        assetAllocationBO2.setFundName("产品3");
        assetAllocationBO2.setFaAccountNo("fund-3");
        assetAllocationBO2.setNav(BigDecimal.TEN);
        assetAllocationBO2.setFundNetValue(new BigDecimal("3.3"));
        assetAllocationBO2.setStockFullPriceAsset(new BigDecimal("4.5"));
        assetAllocationBO2.setStockFullAstNavRatio(new BigDecimal("4.6"));
        assetAllocationBO2.setBondFullPriceAsset(new BigDecimal("5.1"));
        assetAllocationBO2.setBondFullAstNavRatio(new BigDecimal("5.2"));
        assetAllocationBO2.setFundFullPriceAsset(new BigDecimal("5.1"));
        assetAllocationBO2.setFundFullAstNavRatio(new BigDecimal("5.2"));
        assetAllocationBO2.setCashFullPriceAsset(new BigDecimal("5.2"));
        assetAllocationBO2.setCashFullAstNavRatio(new BigDecimal("5.2"));
        assetAllocationBO2.setFmProductFullPriceAsset(new BigDecimal("5.2"));
        assetAllocationBO2.setFmProductFullAstNavRatio(new BigDecimal("5.2"));
        assetAllocationBO2.setOtherFullPriceAsset(new BigDecimal("5.2"));
        assetAllocationBO2.setOtherFullAstNavRatio(new BigDecimal("5.2"));
        assetAllocationBO2.setDebtFullPriceAsset(new BigDecimal("5.2"));
        assetAllocationBO2.setDebtFullAstNavRatio(new BigDecimal("5.2"));

        list.add(assetAllocationBO);
        list.add(assetAllocationBO1);
        list.add(assetAllocationBO2);
        return list;
    }
}
